/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package UserGroup;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author Mukesh
 */
public class AddUserGroup extends HttpServlet {

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        HttpSession session = request.getSession();
        try {
            UserGroupBean ugb = new UserGroupBean();
            ugb.setGroupName(request.getParameter("gname"));
            ugb.setUserType(request.getParameter("userType"));
            int i = UserGroup.Query.addgroup(ugb);
            if (i != 0) {
                session.setAttribute("status", "Success");
                session.setAttribute("msg", "Group ("+ugb.getGroupName()+") Created!");
                response.sendRedirect("/RIT/Settings/Database/AddUserGroup.jsp");
            } else {
                session.setAttribute("status", "Fail");
                session.setAttribute("msg", " Problem in creating Group.");
                response.sendRedirect("/RIT/Settings/Database/AddUserGroup.jsp");
            }
        } catch (Exception e) {
            session.setAttribute("status", "Fail");
            session.setAttribute("msg", " Problem in creating Group.(e)");
            response.sendRedirect("/RIT/Settings/Database/AddUserGroup.jsp");
        } finally {
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
